package controler;

import java.io.Serializable;
import java.util.Collection;

import view.IListView;
import ema.tpjee.banking.dao.SessionFacade;
import ema.tpjee.banking.model.Bank;

public class BankControler implements Serializable {

	
	
	private static final long serialVersionUID = -1645348478746136298L;
	// private BankApplicationDaoImpl dao_;

	private SessionFacade sessionFacade;

	public BankControler() {
		super();
		System.out.println("creating BankControler");
	}

	public Collection<Bank> getList() {
		return sessionFacade.getBankDao().getList();
	}

	public void setList(Collection<Bank> dumm) {

	}

	public void setView(IListView dumm) {
		// this.view = view;
	}

	public void add(Bank b) {
		sessionFacade.getBankDao().add(b);
	}

	public String cancel() {
		System.out.println("action " + this.getClass().getName() + " cancel()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "list";
	}

	public String save() {
		System.out.println("action " + this.getClass().getName() + " save()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		// implicit commit by lifecycle, validators will work
		return "list";
	}

	public String delete() {
		System.out.println("action " + this.getClass().getName() + " delete()");
		sessionFacade.deleteBank();
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "list";
	}

	public String edit() {
		System.out.println("action " + this.getClass().getName() + " edit()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		// sessionFacade.findBank(Integer.parseInt(bankId));
		// sessionFacade.setCurrentBank(sessionFacade.getBankDao().find(Integer.parseInt(bankId)));
		return "edit";
	}

	public String create() {
		System.out.println("action " + this.getClass().getName() + " create()");
		sessionFacade.newBank();
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "edit";
	}

	public String showCustomers() {
		System.out.println("action " + this.getClass().getName()
				+ " showCustomers()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "customers";
	}

	public String next() {
		System.out.println("action " + this.getClass().getName() + " next()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().next(
				(sessionFacade.getCurrentBank())));
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "edit";
	}

	public String prior() {
		System.out.println("action " + this.getClass().getName() + " prior()");
		// sessionFacade.setCurrentBank(nextCustomer(sessionFacade.getCurrentBank()));
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().prior(
				(sessionFacade.getCurrentBank())));
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "edit";
	}

	public String copy() {
		System.out.println("action " + this.getClass().getName() + " copy()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().clone(
				(sessionFacade.getCurrentBank())));
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "list";
	}

	public String foobar() {
		System.out.println("action " + this.getClass().getName() + " foobar()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "edit";
	}

	public void setSessionFacade(SessionFacade sf) {
		this.sessionFacade = sf;
		System.out.println(this.getClass().getName() + " setSessionFacade");
	}

	public String list() {
		System.out.println("action " + this.getClass().getName() + " list()");
		System.out.println("currentBank="
				+ sessionFacade.getCurrentBank().getId());
		return "list";
	}

}
